using System;
using UnityEngine;

public class AchievementsManager : MonoBehaviour
{
	public int Days;

	private void Awake()
	{
		UnityEngine.Object.DontDestroyOnLoad(base.gameObject);
		string text = DateTime.Now.DayOfWeek.ToString();
		Days = PlayerPrefs.GetInt("Days");
		if (!PlayerPrefs.HasKey("LastDay"))
		{
			if (text == "Monday")
			{
				PlayerPrefs.SetString("LastDay", "Sunday");
			}
			if (text == "Tuesday")
			{
				PlayerPrefs.SetString("LastDay", "Monday");
			}
			if (text == "Wednesday")
			{
				PlayerPrefs.SetString("LastDay", "Tuesday");
			}
			if (text == "Thursday")
			{
				PlayerPrefs.SetString("LastDay", "Wednesday");
			}
			if (text == "Friday")
			{
				PlayerPrefs.SetString("LastDay", "Thursday");
			}
			if (text == "Saturday")
			{
				PlayerPrefs.SetString("LastDay", "Friday");
			}
			if (text == "Sunday")
			{
				PlayerPrefs.SetString("LastDay", "Saturday");
			}
		}
		if (text == "Monday" && PlayerPrefs.GetString("LastDay") == "Sunday")
		{
			Days++;
		}
		if (text == "Tuesday" && PlayerPrefs.GetString("LastDay") == "Monday")
		{
			Days++;
		}
		if (text == "Wednesday" && PlayerPrefs.GetString("LastDay") == "Tuesday")
		{
			Days++;
		}
		if (text == "Thursday" && PlayerPrefs.GetString("LastDay") == "Wednesday")
		{
			Days++;
		}
		if (text == "Friday" && PlayerPrefs.GetString("LastDay") == "Thursday")
		{
			Days++;
		}
		if (text == "Saturday" && PlayerPrefs.GetString("LastDay") == "Friday")
		{
			Days++;
		}
		if (text == "Sunday" && PlayerPrefs.GetString("LastDay") == "Saturday")
		{
			Days++;
		}
		if (text == "Monday" && PlayerPrefs.GetString("LastDay") != "Sunday" && text != PlayerPrefs.GetString("LastDay"))
		{
			Days = 0;
		}
		if (text == "Tuesday" && PlayerPrefs.GetString("LastDay") != "Monday" && text != PlayerPrefs.GetString("LastDay"))
		{
			Days = 0;
		}
		if (text == "Wednesday" && PlayerPrefs.GetString("LastDay") != "Tuesday" && text != PlayerPrefs.GetString("LastDay"))
		{
			Days = 0;
		}
		if (text == "Thursday" && PlayerPrefs.GetString("LastDay") != "Wednesday" && text != PlayerPrefs.GetString("LastDay"))
		{
			Days = 0;
		}
		if (text == "Friday" && PlayerPrefs.GetString("LastDay") != "Thursday" && text != PlayerPrefs.GetString("LastDay"))
		{
			Days = 0;
		}
		if (text == "Saturday" && PlayerPrefs.GetString("LastDay") != "Friday" && text != PlayerPrefs.GetString("LastDay"))
		{
			Days = 0;
		}
		if (text == "Sunday" && PlayerPrefs.GetString("LastDay") != "Saturday" && text != PlayerPrefs.GetString("LastDay"))
		{
			Days = 0;
		}
		PlayerPrefs.SetString("LastDay", text);
		PlayerPrefs.SetInt("Days", Days);
		if (Days >= 7)
		{
			UnlockAchievement("CgkI3_DHnsgeEAIQGA");
		}
		PlayerPrefs.SetInt("LastTime", 0);
	}

	private void OnLevelWasLoaded()
	{
		UpdateState();
	}

	public static void UpdateState()
	{
		int value = (int)((float)PlayerPrefs.GetInt("Time") + Time.realtimeSinceStartup - (float)PlayerPrefs.GetInt("LastTime"));
		PlayerPrefs.SetInt("Time", value);
		PlayerPrefs.SetInt("LastTime", (int)Time.realtimeSinceStartup);
		PlayerPrefs.Save();
		if (PlayerPrefs.GetInt("Days") >= 7)
		{
			UnlockAchievement("CgkI3_DHnsgeEAIQGA");
		}
		if (PlayerPrefs.GetInt("Wins") > 0)
		{
			UnlockAchievement("CgkI3_DHnsgeEAIQBQ");
		}
		if (PlayerPrefs.GetInt("Matches Played") > 0)
		{
			UnlockAchievement("CgkI3_DHnsgeEAIQAw");
		}
		if (PlayerPrefs.GetInt("Matches Played") >= 100)
		{
			UnlockAchievement("CgkI3_DHnsgeEAIQBA");
		}
		if (PlayerPrefs.GetInt("Time") >= 3600)
		{
			UnlockAchievement("CgkI3_DHnsgeEAIQBw");
		}
		if (PlayerPrefs.GetInt("Time") >= 14400)
		{
			UnlockAchievement("CgkI3_DHnsgeEAIQCA");
		}
		if (PlayerPrefs.GetInt("Time") >= 86400)
		{
			UnlockAchievement("CgkI3_DHnsgeEAIQCQ");
		}
		if (Time.realtimeSinceStartup >= 3600f)
		{
			UnlockAchievement("CgkI3_DHnsgeEAIQCg");
		}
		if (PlayerPrefs.GetInt("Top1") == 1 && PlayerPrefs.GetInt("Top2") == 1 && PlayerPrefs.GetInt("Top3") == 1 && PlayerPrefs.GetInt("Top4") == 1 && PlayerPrefs.GetInt("Top5") == 1 && PlayerPrefs.GetInt("Top6") == 1 && PlayerPrefs.GetInt("Top7") == 1 && PlayerPrefs.GetInt("Top8") == 1 && PlayerPrefs.GetInt("Top9") == 1 && PlayerPrefs.GetInt("Top10") == 1 && PlayerPrefs.GetInt("Top11") == 1)
		{
			UnlockAchievement("CgkI3_DHnsgeEAIQDg");
		}
		if (PlayerPrefs.GetInt("Wins") >= 365)
		{
			UnlockAchievement("CgkI3_DHnsgeEAIQBg");
		}
		if (PlayerPrefs.GetInt("FallenOut") >= 10)
		{
			JCAchievementMunger.UnlockAchievement("CgkI3_DHnsgeEAIQDw");
		}
		if (PlayerPrefs.GetInt("Stopped") >= 300)
		{
			UnlockAchievement("CgkI3_DHnsgeEAIQEA");
		}
		if (PlayerPrefs.GetInt("rt2") == 1)
		{
			UnlockAchievement("CgkI3_DHnsgeEAIQEg");
		}
		if (PlayerPrefs.GetInt("SCircle1") >= 4321 && PlayerPrefs.GetInt("SCircle2") >= 4321 && PlayerPrefs.GetInt("SCircle3") >= 4321 && PlayerPrefs.GetInt("SCircle4") >= 4321 && PlayerPrefs.GetInt("SCircle5") >= 4321 && PlayerPrefs.GetInt("SCircle6") >= 4321 && PlayerPrefs.GetInt("SCircle7") >= 4321)
		{
			UnlockAchievement("CgkI3_DHnsgeEAIQDQ");
		}
		if (PlayerPrefs.GetInt("SCircle1") >= 4000 || PlayerPrefs.GetInt("SCircle2") >= 4000 || PlayerPrefs.GetInt("SCircle3") >= 4000 || PlayerPrefs.GetInt("SCircle4") >= 4000 || PlayerPrefs.GetInt("SCircle5") >= 4000 || PlayerPrefs.GetInt("SCircle6") >= 4000 || PlayerPrefs.GetInt("SCircle7") >= 4000)
		{
			UnlockAchievement("CgkI3_DHnsgeEAIQCw");
		}
		if (PlayerPrefs.GetInt("SCircle1") > 9000 || PlayerPrefs.GetInt("SCircle2") > 9000 || PlayerPrefs.GetInt("SCircle3") > 9000 || PlayerPrefs.GetInt("SCircle4") > 9000 || PlayerPrefs.GetInt("SCircle5") > 9000 || PlayerPrefs.GetInt("SCircle6") > 9000 || PlayerPrefs.GetInt("SCircle7") > 9000)
		{
			UnlockAchievement("CgkI3_DHnsgeEAIQDA");
		}
		if (PlayerPrefs.GetInt("Exp") >= 1000)
		{
			UnlockAchievement("CgkI3_DHnsgeEAIQFQ");
		}
		if (PlayerPrefs.GetInt("Exp") >= 10000)
		{
			UnlockAchievement("CgkI3_DHnsgeEAIQFg");
		}
	}

	public static void UnlockAchievement(string id)
	{
		if (Social.localUser.authenticated)
		{
			Social.ReportProgress(id, 100.0, delegate(bool success)
			{
				Log(success);
			});
		}
	}

	public static void IncrementAchievement(string id, double progress)
	{
		if (Social.localUser.authenticated)
		{
			Social.ReportProgress(id, progress * 100.0, delegate(bool success)
			{
				Log(success);
			});
		}
	}

	private static void Log(bool success)
	{
		if (!success)
		{
			UnityEngine.Debug.LogError("Failed to unlock achievement");
		}
	}
}
